using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Interactivity;
namespace Microsoft.Expression.Interactivity.Media
{
	public class PlaySoundAction : TriggerAction<DependencyObject>
	{
		public static readonly DependencyProperty SourceProperty = DependencyProperty.Register("Source", typeof(Uri), typeof(PlaySoundAction), null);
		public static readonly DependencyProperty VolumeProperty = DependencyProperty.Register("Volume", typeof(double), typeof(PlaySoundAction), new PropertyMetadata(0.5));
		public Uri Source
		{
			get
			{
				return (Uri)base.GetValue(PlaySoundAction.SourceProperty);
			}
			set
			{
				base.SetValue(PlaySoundAction.SourceProperty, value);
			}
		}
		public double Volume
		{
			get
			{
				return (double)base.GetValue(PlaySoundAction.VolumeProperty);
			}
			set
			{
				base.SetValue(PlaySoundAction.VolumeProperty, value);
			}
		}
		protected virtual void SetMediaElementProperties(MediaElement mediaElement)
		{
			if (mediaElement != null)
			{
				mediaElement.set_Source(this.Source);
				mediaElement.set_Volume(this.Volume);
			}
		}
		protected override void Invoke(object parameter)
		{
			if (!(this.Source == null) && base.AssociatedObject != null)
			{
				Popup popup = new Popup();
				MediaElement mediaElement = new MediaElement();
				popup.set_Child(mediaElement);
				mediaElement.set_Visibility(1);
				this.SetMediaElementProperties(mediaElement);
				mediaElement.add_MediaEnded(delegate(object sender, RoutedEventArgs e)
				{
					popup.set_Child(null);
					popup.set_IsOpen(false);
				});
				mediaElement.add_MediaFailed(delegate(object sender, ExceptionRoutedEventArgs e)
				{
					popup.set_Child(null);
					popup.set_IsOpen(false);
				});
				popup.set_IsOpen(true);
				return;
			}
		}
	}
}
